package leetcode;

/**
 * @创建人 MBY381
 * @创建时间 2022/5/11 17:58
 * @描述 暂无
 */
public class Solution11 {
    public int maxArea(int[] height) {
        if (height.length < 2) {
            return 0;
        }
        int left = 0;
        int right = height.length - 1;
        int ans = 0, leftValue, rightValue,maxHeight=0;
        while (left < right) {
            leftValue = height[left];
            rightValue = height[right];
            if(maxHeight>Math.max(leftValue,rightValue)){
                continue;
            }else {
                maxHeight=Math.max(leftValue,rightValue);
            }
            if (leftValue <= rightValue) {
                ans = Math.max(ans, leftValue*(right-left));
                left++;
            }else {
                ans = Math.max(ans, rightValue*(right-left));
                right--;
            }
        }
        return ans;
    }
}
